#include "data_es.hpp"
#include <thread>
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式， false-调试； true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");
DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    ChatSystem::InitLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto client = ChatSystem::EsClientFactory::create({FLAGS_es_host});
    auto es_user = std::make_shared<ChatSystem::ESUser>(client);
    bool ret = es_user->createIndex();
    es_user->appendData("uid3", "nickname1", "15566667777", "哥只是个传说", "avatar1");
    es_user->appendData("uid4", "nickname2", "15577778888", "写代码的神", "avatar2");

    std::this_thread::sleep_for(std::chrono::seconds(10));

    auto res = es_user->search("ni", {"uid2"});
    for(auto& u : res)
    {
        std::cout << "------------------" << std::endl;
        std::cout << u.user_id() << std::endl;
        std::cout << u.nickname() << std::endl;
        std::cout << u.description() << std::endl;
        std::cout << u.phone() << std::endl;
        std::cout << u.avatar_id() << std::endl;
    }
}